From 40e54ae10094423e8de0a6f8afd1c1c0f56601fd Mon Sep 17 00:00:00 2001 From: "kaf24@scramble.cl.cam.ac.uk" Date: Mon, 12 Jul 2004 15:56:23 +0000 Subject: [PATCH] bitkeeper revision 1.1062.1.8 (40f2b4a7XA6Vy0Lq6nLBErX9_qDhcQ) Various cleanups, and fix a domain-destruct bug that left GDT references hanging. --- .rootkeys | 3 +- xen/arch/x86/dom0_ops.c | 2 +- xen/arch/x86/domain.c | 29 ++++--- xen/arch/x86/memory.c | 2 +- xen/arch/x86/shadow.c | 51 ++++++------ xen/arch/x86/traps.c | 2 +- xen/arch/x86/x86_32/mm.c | 32 +++++--- xen/common/dom0_ops.c | 2 +- xen/common/domain.c | 134 ++------------------------------ xen/common/elf.c | 128 ++++++++++++++++++++++++++++++ xen/common/kernel.c | 2 +- xen/include/asm-x86/domain.h | 17 ++++ xen/include/asm-x86/mm.h | 16 ---- xen/include/asm-x86/processor.h | 3 +- xen/include/asm-x86/shadow.h | 79 ++++++++++--------- xen/include/xen/elf.h | 8 ++ xen/include/xen/mm.h | 9 +++ xen/include/xen/sched.h | 2 + xen/include/xen/shadow.h | 1 - 19 files changed, 282 insertions(+), 240 deletions(-) create mode 100644 xen/common/elf.c create mode 100644 xen/include/asm-x86/domain.h delete mode 100644 xen/include/xen/shadow.h diff --git a/.rootkeys b/.rootkeys index 7a325644bd..b99af7d0b0 100644 --- a/.rootkeys +++ b/.rootkeys @@ -360,6 +360,7 @@ 3ddb79bdLX_P6iB7ILiblRLWvebapg xen/common/dom0_ops.c 3e6377e4i0c9GtKN65e99OtRbw3AZw xen/common/dom_mem_ops.c 3ddb79bdYO5D8Av12NHqPeSviav7cg xen/common/domain.c +40f2b4a27xPOh3R6zD4M_aabz-TDyg xen/common/elf.c 3fba5b96H0khoxNiKbjdi0inpXV-Pw xen/common/event_channel.c 3ddb79bd9drcFPVxd4w2GPOIjLlXpA xen/common/kernel.c 3e4cd9d8LAAghUY0hNIK72uc2ch_Nw xen/common/keyhandler.c @@ -449,6 +450,7 @@ 3ddb79c3r9-31dIsewPV3P3i8HALsQ xen/include/asm-x86/delay.h 3ddb79c34BFiXjBJ_cCKB0aCsV1IDw xen/include/asm-x86/desc.h 40715b2dTokMLYGSuD58BnxOqyWVew xen/include/asm-x86/div64.h +40f2b4a2hC3HtChu-ArD8LyojxWMjg xen/include/asm-x86/domain.h 3e20b82fl1jmQiKdLy7fxMcutfpjWA xen/include/asm-x86/domain_page.h 3ddb79c3NU8Zy40OTrq3D-i30Y3t4A xen/include/asm-x86/fixmap.h 3e2d29944GI24gf7vOP_7x8EyuqxeA xen/include/asm-x86/flushtlb.h @@ -527,7 +529,6 @@ 40589969nPq3DMzv24RDb5LXE9brHw xen/include/xen/sched-if.h 3ddb79c0LzqqS0LhAQ50ekgj4oGl7Q xen/include/xen/sched.h 403a06a7H0hpHcKpAiDe5BPnaXWTlA xen/include/xen/serial.h -40e3392dib7GrcBAu5cT-EUZTYzeEQ xen/include/xen/shadow.h 3ddb79c14dXIhP7C2ahnoD08K90G_w xen/include/xen/slab.h 3ddb79c09xbS-xxfKxuV3JETIhBzmg xen/include/xen/smp.h 3ddb79c1Vi5VleJAOKHAlY0G2zAsgw xen/include/xen/softirq.h diff --git a/xen/arch/x86/dom0_ops.c b/xen/arch/x86/dom0_ops.c index 4ee83fb6ad..5df4c568b4 100644 --- a/xen/arch/x86/dom0_ops.c +++ b/xen/arch/x86/dom0_ops.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #define TRC_DOM0OP_ENTER_BASE 0x00020000 diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index fcc1c75ecc..5d8fd06980 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1,3 +1,9 @@ +/****************************************************************************** + * arch/x86/domain.c + * + * x86-specific domain handling (e.g., register setup and context switching). + */ + /* * Copyright (C) 1995 Linus Torvalds * @@ -23,15 +29,10 @@ #include #include #include -#include +#include #include - #include -extern int loadelfimage(char *); -extern int readelfimage_base_and_size(char *, unsigned long, - unsigned long *, unsigned long *, unsigned long *); - #if !defined(CONFIG_X86_64BITMODE) /* No ring-3 access in initial page tables. */ #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED) @@ -46,7 +47,6 @@ extern int readelfimage_base_and_size(char *, unsigned long, #define round_pgup(_p) (((_p)+(PAGE_SIZE-1))&PAGE_MASK) #define round_pgdown(_p) ((_p)&PAGE_MASK) - int hlt_counter; void disable_hlt(void) @@ -207,12 +207,6 @@ void machine_power_off(void) machine_restart(0); } -/* this belongs in include/asm, but there doesn't seem to be a suitable place */ -void free_perdomain_pt(struct domain *d) -{ - free_page((unsigned long)d->mm.perdomain_pt); -} - void arch_do_createdomain(struct domain *d) { d->shared_info = (void *)get_free_page(); @@ -459,14 +453,19 @@ void domain_relinquish_memory(struct domain *d) write_ptbase(¤t->mm); /* Exit shadow mode before deconstructing final guest page table. */ - if ( shadow_mode(d) ) - shadow_mode_disable(d); + shadow_mode_disable(d); /* Drop the in-use reference to the page-table base. */ if ( pagetable_val(d->mm.pagetable) != 0 ) put_page_and_type(&frame_table[pagetable_val(d->mm.pagetable) >> PAGE_SHIFT]); + /* + * Relinquish GDT mappings. No need for explicit unmapping of the LDT as + * it automatically gets squashed when the guest's mappings go away. + */ + destroy_gdt(d); + /* Relinquish Xen-heap pages. Currently this can only be 'shared_info'. */ page = virt_to_page(d->shared_info); if ( test_and_clear_bit(_PGC_allocated, &page->count_and_flags) ) diff --git a/xen/arch/x86/memory.c b/xen/arch/x86/memory.c index 861bad533f..a2cef38ed2 100644 --- a/xen/arch/x86/memory.c +++ b/xen/arch/x86/memory.c @@ -91,7 +91,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/arch/x86/shadow.c b/xen/arch/x86/shadow.c index dc08bd0199..a611f93c42 100644 --- a/xen/arch/x86/shadow.c +++ b/xen/arch/x86/shadow.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -295,29 +295,30 @@ nomem: return -ENOMEM; } -void shadow_mode_disable( struct domain *p ) +void __shadow_mode_disable(struct domain *d) { - struct mm_struct *m = &p->mm; + struct mm_struct *m = &d->mm; struct shadow_status *next; - __free_shadow_table( m ); + __free_shadow_table(m); m->shadow_mode = 0; SH_LOG("freed tables count=%d l1=%d l2=%d", - m->shadow_page_count, perfc_value(shadow_l1_pages), perfc_value(shadow_l2_pages)); + m->shadow_page_count, perfc_value(shadow_l1_pages), + perfc_value(shadow_l2_pages)); next = m->shadow_ht_extras; - while( next ) + while ( next ) { struct shadow_status * this = next; m->shadow_extras_count--; next = *((struct shadow_status **)(&next[shadow_ht_extra_size])); - kfree( this ); + kfree(this); } SH_LOG("freed extras, now %d", m->shadow_extras_count); - if( m->shadow_dirty_bitmap ) + if ( m->shadow_dirty_bitmap ) { kfree( m->shadow_dirty_bitmap ); m->shadow_dirty_bitmap = 0; @@ -475,53 +476,51 @@ out: return rc; } -int shadow_mode_control( struct domain *p, dom0_shadow_control_t *sc ) +int shadow_mode_control(struct domain *d, dom0_shadow_control_t *sc) { unsigned int cmd = sc->op; int rc = 0; - spin_lock(&p->mm.shadow_lock); + spin_lock(&d->mm.shadow_lock); - if ( p->mm.shadow_mode && cmd == DOM0_SHADOW_CONTROL_OP_OFF ) + if ( cmd == DOM0_SHADOW_CONTROL_OP_OFF ) { - shadow_mode_disable(p); + shadow_mode_disable(d); } else if ( cmd == DOM0_SHADOW_CONTROL_OP_ENABLE_TEST ) { - if(p->mm.shadow_mode) shadow_mode_disable(p); - shadow_mode_enable(p, SHM_test); + shadow_mode_disable(d); + shadow_mode_enable(d, SHM_test); } else if ( cmd == DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY ) { - if(p->mm.shadow_mode) shadow_mode_disable(p); - shadow_mode_enable(p, SHM_logdirty); + shadow_mode_disable(d); + shadow_mode_enable(d, SHM_logdirty); } - else if ( p->mm.shadow_mode && cmd >= DOM0_SHADOW_CONTROL_OP_FLUSH && cmd<=DOM0_SHADOW_CONTROL_OP_CLEAN2 ) + else if ( shadow_mode(d) && + (cmd >= DOM0_SHADOW_CONTROL_OP_FLUSH) && + (cmd <= DOM0_SHADOW_CONTROL_OP_CLEAN2) ) { - rc = shadow_mode_table_op(p, sc); + rc = shadow_mode_table_op(d, sc); } else { rc = -EINVAL; } - flush_tlb_cpu(p->processor); + flush_tlb_cpu(d->processor); - spin_unlock(&p->mm.shadow_lock); + spin_unlock(&d->mm.shadow_lock); return rc; } - - -static inline struct pfn_info *alloc_shadow_page( struct mm_struct *m ) +static inline struct pfn_info *alloc_shadow_page(struct mm_struct *m) { m->shadow_page_count++; - - return alloc_domain_page( NULL ); + return alloc_domain_page(NULL); } - void unshadow_table( unsigned long gpfn, unsigned int type ) { unsigned long spfn; diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index c43aafea23..aa74ae4dfe 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/xen/arch/x86/x86_32/mm.c b/xen/arch/x86/x86_32/mm.c index 59e304e4a7..d034240b41 100644 --- a/xen/arch/x86/x86_32/mm.c +++ b/xen/arch/x86/x86_32/mm.c @@ -212,13 +212,26 @@ int check_descriptor(unsigned long a, unsigned long b) } -long set_gdt(struct domain *p, +void destroy_gdt(struct domain *d) +{ + int i; + unsigned long pfn; + + for ( i = 0; i < 16; i++ ) + { + if ( (pfn = l1_pgentry_to_pagenr(d->mm.perdomain_pt[i])) != 0 ) + put_page_and_type(&frame_table[pfn]); + d->mm.perdomain_pt[i] = mk_l1_pgentry(0); + } +} + + +long set_gdt(struct domain *d, unsigned long *frames, unsigned int entries) { /* NB. There are 512 8-byte entries per GDT page. */ int i, nr_pages = (entries + 511) / 512; - unsigned long pfn; struct desc_struct *vgdt; /* Check the new GDT. */ @@ -226,7 +239,7 @@ long set_gdt(struct domain *p, { if ( unlikely(frames[i] >= max_page) || unlikely(!get_page_and_type(&frame_table[frames[i]], - p, PGT_gdt_page)) ) + d, PGT_gdt_page)) ) goto fail; } @@ -238,20 +251,15 @@ long set_gdt(struct domain *p, unmap_domain_mem(vgdt); /* Tear down the old GDT. */ - for ( i = 0; i < 16; i++ ) - { - if ( (pfn = l1_pgentry_to_pagenr(p->mm.perdomain_pt[i])) != 0 ) - put_page_and_type(&frame_table[pfn]); - p->mm.perdomain_pt[i] = mk_l1_pgentry(0); - } + destroy_gdt(d); /* Install the new GDT. */ for ( i = 0; i < nr_pages; i++ ) - p->mm.perdomain_pt[i] = + d->mm.perdomain_pt[i] = mk_l1_pgentry((frames[i] << PAGE_SHIFT) | __PAGE_HYPERVISOR); - SET_GDT_ADDRESS(p, GDT_VIRT_START); - SET_GDT_ENTRIES(p, (entries*8)-1); + SET_GDT_ADDRESS(d, GDT_VIRT_START); + SET_GDT_ENTRIES(d, (entries*8)-1); return 0; diff --git a/xen/common/dom0_ops.c b/xen/common/dom0_ops.c index fcec8991b2..3af08f0731 100644 --- a/xen/common/dom0_ops.c +++ b/xen/common/dom0_ops.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #define TRC_DOM0OP_ENTER_BASE 0x00020000 diff --git a/xen/common/domain.c b/xen/common/domain.c index 3df97a7e25..a2b83768cd 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1,3 +1,8 @@ +/****************************************************************************** + * domain.c + * + * Generic domain-handling functions. + */ #include #include @@ -8,8 +13,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -19,11 +23,6 @@ rwlock_t tasklist_lock __cacheline_aligned = RW_LOCK_UNLOCKED; struct domain *task_hash[TASK_HASH_SIZE]; struct domain *task_list; -extern void arch_do_createdomain(struct domain *); -extern void arch_final_setup_guestos(struct domain *, full_execution_context_t *c); -extern void free_perdomain_pt(struct domain *); -extern void domain_relinquish_memory(struct domain *d); - struct domain *do_createdomain(domid_t dom_id, unsigned int cpu) { char buf[100]; @@ -395,124 +394,7 @@ int final_setup_guestos(struct domain *p, dom0_builddomain_t *builddomain) set_bit(DF_CONSTRUCTED, &p->flags); out: - if (c) kfree(c); - + if ( c != NULL ) + kfree(c); return rc; } - -static inline int is_loadable_phdr(Elf_Phdr *phdr) -{ - return ((phdr->p_type == PT_LOAD) && - ((phdr->p_flags & (PF_W|PF_X)) != 0)); -} - -int readelfimage_base_and_size(char *elfbase, - unsigned long elfsize, - unsigned long *pkernstart, - unsigned long *pkernend, - unsigned long *pkernentry) -{ - Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase; - Elf_Phdr *phdr; - Elf_Shdr *shdr; - unsigned long kernstart = ~0UL, kernend=0UL; - char *shstrtab, *guestinfo; - int h; - - if ( !IS_ELF(*ehdr) ) - { - printk("Kernel image does not have an ELF header.\n"); - return -EINVAL; - } - - if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize ) - { - printk("ELF program headers extend beyond end of image.\n"); - return -EINVAL; - } - - if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize ) - { - printk("ELF section headers extend beyond end of image.\n"); - return -EINVAL; - } - - /* Find the section-header strings table. */ - if ( ehdr->e_shstrndx == SHN_UNDEF ) - { - printk("ELF image has no section-header strings table (shstrtab).\n"); - return -EINVAL; - } - shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + - (ehdr->e_shstrndx*ehdr->e_shentsize)); - shstrtab = elfbase + shdr->sh_offset; - - /* Find the special '__xen_guest' section and check its contents. */ - for ( h = 0; h < ehdr->e_shnum; h++ ) - { - shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + (h*ehdr->e_shentsize)); - if ( strcmp(&shstrtab[shdr->sh_name], "__xen_guest") != 0 ) - continue; - guestinfo = elfbase + shdr->sh_offset; - printk("Xen-ELF header found: '%s'\n", guestinfo); - if ( (strstr(guestinfo, "GUEST_OS=linux") == NULL) || - (strstr(guestinfo, "XEN_VER=1.3") == NULL) ) - { - printk("ERROR: Xen will only load Linux built for Xen v1.3\n"); - return -EINVAL; - } - break; - } - if ( h == ehdr->e_shnum ) - { - printk("Not a Xen-ELF image: '__xen_guest' section not found.\n"); - return -EINVAL; - } - - for ( h = 0; h < ehdr->e_phnum; h++ ) - { - phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize)); - if ( !is_loadable_phdr(phdr) ) - continue; - if ( phdr->p_vaddr < kernstart ) - kernstart = phdr->p_vaddr; - if ( (phdr->p_vaddr + phdr->p_memsz) > kernend ) - kernend = phdr->p_vaddr + phdr->p_memsz; - } - - if ( (kernstart > kernend) || - (ehdr->e_entry < kernstart) || - (ehdr->e_entry > kernend) ) - { - printk("Malformed ELF image.\n"); - return -EINVAL; - } - - *pkernstart = kernstart; - *pkernend = kernend; - *pkernentry = ehdr->e_entry; - - return 0; -} - -int loadelfimage(char *elfbase) -{ - Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase; - Elf_Phdr *phdr; - int h; - - for ( h = 0; h < ehdr->e_phnum; h++ ) - { - phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize)); - if ( !is_loadable_phdr(phdr) ) - continue; - if ( phdr->p_filesz != 0 ) - memcpy((char *)phdr->p_vaddr, elfbase + phdr->p_offset, - phdr->p_filesz); - if ( phdr->p_memsz > phdr->p_filesz ) - memset((char *)phdr->p_vaddr + phdr->p_filesz, 0, - phdr->p_memsz - phdr->p_filesz); - } - - return 0; -} diff --git a/xen/common/elf.c b/xen/common/elf.c new file mode 100644 index 0000000000..72f1617a32 --- /dev/null +++ b/xen/common/elf.c @@ -0,0 +1,128 @@ +/****************************************************************************** + * elf.c + * + * Generic Elf-loading routines. + */ + +#include +#include +#include +#include +#include + +static inline int is_loadable_phdr(Elf_Phdr *phdr) +{ + return ((phdr->p_type == PT_LOAD) && + ((phdr->p_flags & (PF_W|PF_X)) != 0)); +} + +int readelfimage_base_and_size(char *elfbase, + unsigned long elfsize, + unsigned long *pkernstart, + unsigned long *pkernend, + unsigned long *pkernentry) +{ + Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase; + Elf_Phdr *phdr; + Elf_Shdr *shdr; + unsigned long kernstart = ~0UL, kernend=0UL; + char *shstrtab, *guestinfo; + int h; + + if ( !IS_ELF(*ehdr) ) + { + printk("Kernel image does not have an ELF header.\n"); + return -EINVAL; + } + + if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize ) + { + printk("ELF program headers extend beyond end of image.\n"); + return -EINVAL; + } + + if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize ) + { + printk("ELF section headers extend beyond end of image.\n"); + return -EINVAL; + } + + /* Find the section-header strings table. */ + if ( ehdr->e_shstrndx == SHN_UNDEF ) + { + printk("ELF image has no section-header strings table (shstrtab).\n"); + return -EINVAL; + } + shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + + (ehdr->e_shstrndx*ehdr->e_shentsize)); + shstrtab = elfbase + shdr->sh_offset; + + /* Find the special '__xen_guest' section and check its contents. */ + for ( h = 0; h < ehdr->e_shnum; h++ ) + { + shdr = (Elf_Shdr *)(elfbase + ehdr->e_shoff + (h*ehdr->e_shentsize)); + if ( strcmp(&shstrtab[shdr->sh_name], "__xen_guest") != 0 ) + continue; + guestinfo = elfbase + shdr->sh_offset; + printk("Xen-ELF header found: '%s'\n", guestinfo); + if ( (strstr(guestinfo, "GUEST_OS=linux") == NULL) || + (strstr(guestinfo, "XEN_VER=1.3") == NULL) ) + { + printk("ERROR: Xen will only load Linux built for Xen v1.3\n"); + return -EINVAL; + } + break; + } + if ( h == ehdr->e_shnum ) + { + printk("Not a Xen-ELF image: '__xen_guest' section not found.\n"); + return -EINVAL; + } + + for ( h = 0; h < ehdr->e_phnum; h++ ) + { + phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize)); + if ( !is_loadable_phdr(phdr) ) + continue; + if ( phdr->p_vaddr < kernstart ) + kernstart = phdr->p_vaddr; + if ( (phdr->p_vaddr + phdr->p_memsz) > kernend ) + kernend = phdr->p_vaddr + phdr->p_memsz; + } + + if ( (kernstart > kernend) || + (ehdr->e_entry < kernstart) || + (ehdr->e_entry > kernend) ) + { + printk("Malformed ELF image.\n"); + return -EINVAL; + } + + *pkernstart = kernstart; + *pkernend = kernend; + *pkernentry = ehdr->e_entry; + + return 0; +} + +int loadelfimage(char *elfbase) +{ + Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase; + Elf_Phdr *phdr; + int h; + + for ( h = 0; h < ehdr->e_phnum; h++ ) + { + phdr = (Elf_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize)); + if ( !is_loadable_phdr(phdr) ) + continue; + if ( phdr->p_filesz != 0 ) + memcpy((char *)phdr->p_vaddr, elfbase + phdr->p_offset, + phdr->p_filesz); + if ( phdr->p_memsz > phdr->p_filesz ) + memset((char *)phdr->p_vaddr + phdr->p_filesz, 0, + phdr->p_memsz - phdr->p_filesz); + } + + return 0; +} diff --git a/xen/common/kernel.c b/xen/common/kernel.c index a2b06acc9d..2f99bbee43 100644 --- a/xen/common/kernel.c +++ b/xen/common/kernel.c @@ -19,8 +19,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h new file mode 100644 index 0000000000..e299f616b0 --- /dev/null +++ b/xen/include/asm-x86/domain.h @@ -0,0 +1,17 @@ + +#ifndef __ASM_X86_DOMAIN_H__ +#define __ASM_X86_DOMAIN_H__ + +extern void arch_do_createdomain(struct domain *d); + +extern void arch_final_setup_guestos( + struct domain *d, full_execution_context_t *c); + +static inline void free_perdomain_pt(struct domain *d) +{ + free_page((unsigned long)d->mm.perdomain_pt); +} + +extern void domain_relinquish_memory(struct domain *d); + +#endif /* __ASM_X86_DOMAIN_H__ */ diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index ffa8797fa9..0586562c62 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -3,9 +3,6 @@ #define __ASM_X86_MM_H__ #include -#ifdef LINUX_2_6 -#include -#endif #include #include #include @@ -19,19 +16,6 @@ #include -/* - * The following is for page_alloc.c. - */ - -void init_page_allocator(unsigned long min, unsigned long max); -unsigned long __get_free_pages(int order); -void __free_pages(unsigned long p, int order); -#define get_free_page() (__get_free_pages(0)) -#define __get_free_page() (__get_free_pages(0)) -#define free_pages(_p,_o) (__free_pages(_p,_o)) -#define free_page(_p) (__free_pages(_p,0)) - - /* * Per-page-frame information. */ diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h index bbd682e280..11060e3c49 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -406,7 +406,8 @@ static inline void write_ptbase(struct mm_struct *mm) #define GET_GDT_ENTRIES(_p) ((*(u16 *)((_p)->mm.gdt + 0))) #define GET_GDT_ADDRESS(_p) ((*(unsigned long *)((_p)->mm.gdt + 2))) -long set_gdt(struct domain *p, +void destroy_gdt(struct domain *d); +long set_gdt(struct domain *d, unsigned long *frames, unsigned int entries); diff --git a/xen/include/asm-x86/shadow.h b/xen/include/asm-x86/shadow.h index df24329b2b..494a301220 100644 --- a/xen/include/asm-x86/shadow.h +++ b/xen/include/asm-x86/shadow.h @@ -24,16 +24,26 @@ #define shadow_linear_pg_table ((l1_pgentry_t *)SH_LINEAR_PT_VIRT_START) #define shadow_linear_l2_table ((l2_pgentry_t *)(SH_LINEAR_PT_VIRT_START+(SH_LINEAR_PT_VIRT_START>>(L2_PAGETABLE_SHIFT-L1_PAGETABLE_SHIFT)))) +#define shadow_mode(_d) ((_d)->mm.shadow_mode) +#define shadow_lock_init(_d) spin_lock_init(&(_d)->mm.shadow_lock) + extern void shadow_mode_init(void); -extern int shadow_mode_control( struct domain *p, dom0_shadow_control_t *sc ); -extern int shadow_fault( unsigned long va, long error_code ); -extern void shadow_l1_normal_pt_update( unsigned long pa, unsigned long gpte, - unsigned long *prev_spfn_ptr, - l1_pgentry_t **prev_spl1e_ptr ); -extern void shadow_l2_normal_pt_update( unsigned long pa, unsigned long gpte ); -extern void unshadow_table( unsigned long gpfn, unsigned int type ); -extern int shadow_mode_enable( struct domain *p, unsigned int mode ); -extern void shadow_mode_disable( struct domain *p ); +extern int shadow_mode_control(struct domain *p, dom0_shadow_control_t *sc); +extern int shadow_fault(unsigned long va, long error_code); +extern void shadow_l1_normal_pt_update(unsigned long pa, unsigned long gpte, + unsigned long *prev_spfn_ptr, + l1_pgentry_t **prev_spl1e_ptr); +extern void shadow_l2_normal_pt_update(unsigned long pa, unsigned long gpte); +extern void unshadow_table(unsigned long gpfn, unsigned int type); +extern int shadow_mode_enable(struct domain *p, unsigned int mode); + +extern void __shadow_mode_disable(struct domain *d); +static inline void shadow_mode_disable(struct domain *d) +{ + if ( shadow_mode(d) ) + __shadow_mode_disable(d); +} + extern unsigned long shadow_l2_table( struct mm_struct *m, unsigned long gpfn ); @@ -75,11 +85,6 @@ printk("DOM%u: (file=shadow.c, line=%d) " _f "\n", \ #endif -/************************************************************************/ - -#define shadow_mode(d) (d->mm.shadow_mode) -#define shadow_lock_init(d) spin_lock_init(&d->mm.shadow_lock) - /************************************************************************/ static inline int __mark_dirty( struct mm_struct *m, unsigned int mfn ) @@ -100,14 +105,14 @@ static inline int __mark_dirty( struct mm_struct *m, unsigned int mfn ) ASSERT(m->shadow_dirty_bitmap); if( likely(pfnshadow_dirty_bitmap_size) ) { - /* These updates occur with mm.shadow_lock held, so use - (__) version of test_and_set */ - if( __test_and_set_bit( pfn, m->shadow_dirty_bitmap ) == 0 ) - { - // if we set it - m->shadow_dirty_count++; - rc = 1; - } + /* These updates occur with mm.shadow_lock held, so use + (__) version of test_and_set */ + if ( __test_and_set_bit( pfn, m->shadow_dirty_bitmap ) == 0 ) + { + // if we set it + m->shadow_dirty_count++; + rc = 1; + } } else { @@ -119,7 +124,7 @@ static inline int __mark_dirty( struct mm_struct *m, unsigned int mfn ) frame_table[mfn].count_and_flags, frame_table[mfn].type_and_flags ); } - + return rc; } @@ -138,13 +143,13 @@ static inline int mark_dirty( struct mm_struct *m, unsigned int mfn ) /************************************************************************/ -static inline void l1pte_write_fault( struct mm_struct *m, - unsigned long *gpte_p, unsigned long *spte_p ) +static inline void l1pte_write_fault( + struct mm_struct *m, unsigned long *gpte_p, unsigned long *spte_p) { unsigned long gpte = *gpte_p; unsigned long spte = *spte_p; - switch( m->shadow_mode ) + switch ( m->shadow_mode ) { case SHM_test: spte = gpte; @@ -164,13 +169,13 @@ static inline void l1pte_write_fault( struct mm_struct *m, *spte_p = spte; } -static inline void l1pte_read_fault( struct mm_struct *m, - unsigned long *gpte_p, unsigned long *spte_p ) +static inline void l1pte_read_fault( + struct mm_struct *m, unsigned long *gpte_p, unsigned long *spte_p) { unsigned long gpte = *gpte_p; unsigned long spte = *spte_p; - switch( m->shadow_mode ) + switch ( m->shadow_mode ) { case SHM_test: spte = gpte; @@ -192,13 +197,13 @@ static inline void l1pte_read_fault( struct mm_struct *m, *spte_p = spte; } -static inline void l1pte_no_fault( struct mm_struct *m, - unsigned long *gpte_p, unsigned long *spte_p ) +static inline void l1pte_no_fault( + struct mm_struct *m, unsigned long *gpte_p, unsigned long *spte_p) { unsigned long gpte = *gpte_p; unsigned long spte = *spte_p; - switch( m->shadow_mode ) + switch ( m->shadow_mode ) { case SHM_test: spte = 0; @@ -227,9 +232,11 @@ static inline void l1pte_no_fault( struct mm_struct *m, *spte_p = spte; } -static inline void l2pde_general( struct mm_struct *m, - unsigned long *gpde_p, unsigned long *spde_p, - unsigned long sl1pfn) +static inline void l2pde_general( + struct mm_struct *m, + unsigned long *gpde_p, + unsigned long *spde_p, + unsigned long sl1pfn) { unsigned long gpde = *gpde_p; unsigned long spde = *spde_p; @@ -256,8 +263,6 @@ static inline void l2pde_general( struct mm_struct *m, /*********************************************************************/ - - #if SHADOW_HASH_DEBUG static void shadow_audit(struct mm_struct *m, int print) { diff --git a/xen/include/xen/elf.h b/xen/include/xen/elf.h index ecf6bbca97..c66aeb0d3d 100644 --- a/xen/include/xen/elf.h +++ b/xen/include/xen/elf.h @@ -24,6 +24,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#ifndef __XEN_ELF_H__ +#define __XEN_ELF_H__ + typedef u8 Elf_Byte; typedef u32 Elf32_Addr; /* Unsigned program address */ @@ -521,3 +524,8 @@ typedef struct { #define AuxInfo Aux64Info #endif +extern int loadelfimage(char *); +extern int readelfimage_base_and_size( + char *, unsigned long, unsigned long *, unsigned long *, unsigned long *); + +#endif /* __XEN_ELF_H__ */ diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 13cc33afcc..0ad445b32b 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -2,6 +2,15 @@ #ifndef __XEN_MM_H__ #define __XEN_MM_H__ +/* page_alloc.c */ +void init_page_allocator(unsigned long min, unsigned long max); +unsigned long __get_free_pages(int order); +void __free_pages(unsigned long p, int order); +#define get_free_page() (__get_free_pages(0)) +#define __get_free_page() (__get_free_pages(0)) +#define free_pages(_p,_o) (__free_pages(_p,_o)) +#define free_page(_p) (__free_pages(_p,0)) + #include #endif /* __XEN_MM_H__ */ diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index f8a9981a5d..d75257bf7c 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -295,4 +295,6 @@ static inline void domain_unpause_by_systemcontroller(struct domain *d) #define IS_PRIV(_d) (test_bit(DF_PRIVILEGED, &(_d)->flags)) #define IS_CAPABLE_PHYSDEV(_d) (test_bit(DF_PHYSDEV, &(_d)->flags)) +#include + #endif /* __SCHED_H__ */ diff --git a/xen/include/xen/shadow.h b/xen/include/xen/shadow.h deleted file mode 100644 index c59e02e14c..0000000000 --- a/xen/include/xen/shadow.h +++ /dev/null @@ -1 +0,0 @@ -#include -- 2.30.2